
% end products
ep_names = [1 2 3 4 5 6 7 8 9 10]; %[1 2 3 4 5];
earliest_release_indices = [1 1 1 1 1 1 1 1 1 1]; %[1 1 1 1 1];
due_indices = [10 10 10 10 10 10 10 10 10 10]; %[5 5 5 5 5];

% end product part requirements
part_names = [1 2 3 4 5 6]; %[1 2 3 4];
ep_part_req = [12 4 18 34 55 3 6 19 8 22; 44 22 44 66 77 8 3 5 9 11; 9 5 3 4 6 2 8 7 1 4; 6 5 7 9 2 1 4 6 7 2; 6 2 9 8 4 2 4 5 4 3; 24 14 12 16 14 18 22 28 29 17;]; %[12 16 16 14 12; 12 9 9 15 15; 1 1 1 1 1; 24 18 18 30 30];
part_smoothing_intervals = [2 2 2 2 2 2]; %[2 2 2 2];
part_weights = [1 1 1 1 1 1]; %[1 1 1 1];

% preprocessing will remove parts which do not influence the final outcome
[part_names_pp, part_req_pp, smoothing_intervals_pp, part_weights_pp] = preprocess(ep_names, part_names, ep_part_req, part_smoothing_intervals, part_weights);

m = length(ep_names);
% organize data for each end product in rows for easy swapping
products = cell(m, 4);
for i = 1:m
    p = ep_names(i);
    products(p,1:3) = num2cell([p earliest_release_indices(p) due_indices(p)], 1);
    products(p,4) = {part_req_pp(:, p)}; % convert part requirement to cell
end

[products_init_seq] = feasability(products)
if isempty(products_init_seq)
    print 'no feasible initial sequence was found';
    exit;
end

[ep_final_seq] = interchange(products_init_seq, part_names_pp, smoothing_intervals_pp, part_weights_pp, products, part_names_pp, smoothing_intervals_pp, part_weights_pp)